home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / MAGS.ZIP / VLAD#4.ZIP / ARTICLE.2_2 < prev    next >
Encoding:
Text File  |  1995-03-30  |  38.6 KB  |  791 lines

  1.  
  2.  
  3.                             F I G H T   B A C K  !
  4.                           --------------------------
  5.  
  6.                           (c) 1995 by Sauron's Mouth
  7.  
  8.  
  9.  1. READ THIS!
  10.  
  11.  This document is dedicated to all virus writers which think that just barely
  12.  finishing a virus is a good job. It's lame! There are thousands of primitive
  13.  viruses which don't have stealth, aren't polymorphic or don't even have any
  14.  retro structures. A lot of viruses aren't bug free and won't spread far.
  15.  If you aren't skilled enough to code a full-stealth virus or a polymorphic
  16.  engine and feel great when finishing another lame non-resident virus then
  17.  stop reading this.  Most likely this stuff is beyond your wildest dreams.
  18.  AV's are invited to read on. Just see how weak your 'protection' is.
  19.  
  20.  In this document you will find tricks to bypass or disable AV software and
  21.  ways to make the life of the AV people even harder. I will not give you
  22.  complete sources, try yourself. If you write viruses just to infect other
  23.  people or destroy data then piss off. Coding is fun, and this should be the
  24.  only reason to make viruses. But let's start with the real stuff.
  25.  
  26.  
  27.  2. BASIC STRUCTURES
  28.  
  29.  Most AV programs have weak spots. Some of the AV programs have A LOT of weak
  30.  spots. But before starting with retro structures I suggest you consider this
  31.  for your virus:
  32.      - Don't infect programs with internal overlays. They will be corrupted
  33.        or won't work anymore after infection. It's very easy to check this:
  34.        compare the real file size (maybe with i21/4202 CX=DX=0) with the code
  35.        size indicated in the EXE header (offset 2 and 4 plus paragraphs in
  36.        header) It's also a good idea to check for 40h at offset 18h in the
  37.        EXE header.
  38.  
  39.      - Don't (!) reset INT 13h while infecting files. This will corrupt your
  40.        hard disk very fast when a disk cache is used.
  41.  
  42.      - Set all registers (AX-DX, SI/DI/BP) to zero before returning to the
  43.        host program. This will prevent trouble with programs which require
  44.        command-line parameters.
  45.  
  46.      - Use extra memory. It's very easy to use UMB, HMA or EMS memory.
  47.        See i21h/5803h (DOS-UMB), i2Fh/4310h (XMS-UMB/HMA) and i67 (EMS).
  48.        Keep in mind that when staying resident in the HMA you can only use
  49.        INT 13h for reading/writing. INT 21/3F and 40 don't function there.
  50.        There's still some virus scanners which just scan the memory up to
  51.        640K, for example TNTVIRUS and it's derivates CPAV & MSAV.
  52.        Don't resize the last MCB or reduce the top of memory. There's a lot
  53.        of tools which can detect this.
  54.  
  55.      - Set INT 24h to [MOV AL,3 / IRET] while infecting files. This will
  56.        suppress error messages when infecting files on write protected disks.
  57.        This is stupid, but there's still viruses which don't do this.
  58.  
  59.      - Wipe the file attributes before opening a program and restore them
  60.        after the infection. Viruses that can't infect READ-ONLY files are
  61.        lame.  Also keep the file time stamp during infection.
  62.  
  63.      - Setup a correct new stack for infected EXE files. Don't use CS=SS
  64.        but SS=CS+1 and avoid odd SP values. To make the testing of cleaners
  65.        a bit more difficult you should also increase MINIMAL PARAGRAPHS
  66.        NEEDED in the EXE header. If you make this, the AV people can't use a
  67.        simple file compare to validate the cleaned file.
  68.  
  69.      - Use anti-heuristic structures. There's alot of virus scanners with
  70.        heuristics now. F-PROT isn't that good, but TBSCAN and AVP are really
  71.        good at detecting unknown viruses.
  72.  
  73.        Don't use
  74.  
  75.           CMP AX,4B00h      but maybe     XCHG AX,BX
  76.           JE  Label_1                     CMP  BX,4B00h
  77.                                           XCHG AX,BX
  78.                                           JE   Label_1
  79.  
  80.        There are thousands of ways of varying this. Be creative!
  81.        Especially the example above is very often detected, for example by
  82.        the heuristic memory-scanning (!) of AVP.
  83.  
  84.        There are other structures you should really avoid:
  85.  
  86.        CMP [0],"Z"       (Search for last MCB)
  87.  
  88.        MOV [1],8         (Mark MCB as system area)
  89.  
  90.        SUB [3],xxxx      (Cut MCB by xxxx paragraphs)
  91.  
  92.        MOV AX,2521h      (Hook INT 21h)
  93.        INT 21h
  94.  
  95.        MOV [84],xxxx     (Hook INT 21h directly)
  96.        MOV [86],cs
  97.  
  98.        MOV AX,[413] /    (Modify top of memory)
  99.        MOV [413],AX
  100.  
  101.        CALL $+3          (Get current IP)
  102.        POP SI
  103.  
  104.        CMP [xxxx],"ZM"   (Check for EXE file)
  105.        CMP AX,"ZM"
  106.  
  107.        CMP [xxxx],"XE"   (Check for COM or EXE extension)
  108.        CMP [xxxx],"OC"
  109.  
  110.        MOV DI,100h       (Restore the header of a COM program)
  111.        MOVSW
  112.        MOVSB
  113.  
  114.        MOV [100h],xxxx
  115.        MOV [102h],yy
  116.  
  117.        MOV AX,100h       (Jump back to COM starting IP)
  118.        PUSH AX
  119.        RET
  120.  
  121.        MOV AX,100h
  122.        JMP AX
  123.  
  124.        MOV AX,F592h      (Installation check)
  125.        INT 21h
  126.        CMP AX,2343h
  127.  
  128.  3. ADVANCED STRUCTURES
  129.  
  130.  3.1 Full-stealth (file level):
  131.      Many viruses just have semi-stealth, but it's very easy to make a virus
  132.      full-stealth. In my opinion this belongs to the basic structures of a
  133.      virus, and every virus should be at least full-stealth.
  134.  
  135.      There are two ways to achieve full-stealth:
  136.  
  137.      1. Clean infected programs at i21/3Dxx. This has some advantages but
  138.         causes many other problems. It won't work on write protected disks,
  139.         it's slow (ok, most people uses disk caches) and very primitive.
  140.         It's effective against MSAV/CPAV anti-stealth and should
  141.         be enabled when MSAV.EXE or CPAV.EXE is executed.
  142.         (But who's is using this rubbish anyway?)
  143.      2. The more professional way is to clean infected files during reading.
  144.         Just intercept the following i21 functions:
  145.         AH=11/12 - Just do normal semi-stealth (SUB ES:[BX+1C],Vir_Length)
  146.         AH=4E/4F - Same as above
  147.         AH=3F    - This is the most difficult part of the code. First of all,
  148.                    check if the opened file is infected. You should store the
  149.                    complete original file header behind the virus code if you
  150.                    infect a file, you'll need it now.
  151.         AH=40    - Check if the file is infected and if true clean it before
  152.                    allowing the write access.
  153.         AX=4202  - You don't have to handle 4200 or 4201. Just take care of
  154.                    subfunction 2 because it sets the file pointer relative to
  155.                    the file end. Allow the interrupt and subtract the virus
  156.                    size from the resulting DX:AX pointer.
  157.         AX=4B01  - This is used by debuggers. Just clean the file completely
  158.                    before allowing this call.
  159.  
  160.         The following situations must be handled with i21/3F:
  161.  
  162.          0        18h
  163.          ########################################################
  164.          # Header # Program        # Virus    # Original Header #
  165.          ########################################################
  166.          +++++            (Read access from 0 to <18h)
  167.            +++            (Read access from >0 to <18h)
  168.          +++++++++====    (Read access from 0 to >18h)
  169.               ++++==      (Read access from >0 to >18h)
  170.  
  171.          In this case the read access is just around the file header.
  172.          Just copy the neccessary part from the original header into
  173.          the read buffer. Be careful, the read access could start at
  174.          file offset <> 0.
  175.  
  176.          ########################################################
  177.          # Header # Program        # Virus    # Original Header #
  178.          ########################################################
  179.                      ============
  180.                          ==========+++++
  181.                                      ++++++++++++++++++
  182.  
  183.          The first case can be ignored. The second one crosses the border
  184.          and reads into the virus area. In this case just cut the read to
  185.          the legal program area. If you change the CX of the read remember to
  186.          restore it before returning to the host program! The third case is
  187.          very easy to handle, just return Carry=0 and AX=0 to the host.
  188.          You should check the ranges BEFORE the read access. If not, you
  189.          must also handle the correct setting of the file pointer.
  190.  
  191.          ########################################################
  192.          # Header # Program        # Virus    # Original Header #
  193.          ########################################################
  194.             ++++++=================++++++++++++++++++ (Read access)
  195.  
  196.          Of course your virus must be able to handle combinations of the
  197.          mentioned situations.
  198.  
  199.      Some virus coders obviously don't know the RETF 2 operand. If you have
  200.      to abort an interrupt and need special flags use RETF 2 instead if IRET.
  201.      Example:
  202.  
  203.                  CMP     AX,4202h                ; Set file pointer?
  204.                  JNE     Lbl_1
  205.                  CALL    Check_If_Infected       ; File is infected?
  206.                  JNE     Lbl_1
  207.                  PUSHF                           ; Call i21
  208.                  CALL    CS:DWORD PTR [Old_Int21]
  209.                  JC      Lbl_2                   ; Error?
  210.                  PUSHF
  211.                  SUB     AX,Virus_Length         ; Adjust with virus length
  212.                  SBB     DX,0
  213.                  POPF
  214.          Lbl_2:  RETF    2               ; Return without restoring the flags
  215.  
  216.          Lbl_1:
  217.  
  218.      A good way to check your stealth routine is FC and CHKSAFE and a binary
  219.      file viewer.
  220.  
  221.      How to mark infected files? Most stealth viruses add 100 years to the
  222.      file date or set the seconds field to 60 or 62. Don't use this! A lot of
  223.      AV programs detect this (primitive heuristic) and also some AV-TSRs
  224.      will warn the user about files with an illegal time stamp. (TBFILE)
  225.      I've seen two solutions for this problem:
  226.  
  227.        1. Just set a static 'legal' time stamp, maybe SECONDS=2 or a complete
  228.           new time stamp as 4-1-94. Keep in mind that you can't restore this
  229.           back to the original state when intercepting i21/11/12/4E/4F.
  230.           Some integrity checkers will warn the user if the time stamp has
  231.           changed, regardless as to whether the other file attributes are 
  232.           'unchanged'.
  233.        2. Size padding is quite complicated in combination with full-stealth
  234.           when you want to return the original file size. You have to open
  235.           the file and get the stored information. This is done by Havoc or
  236.           N8FALL, but this also slows down the execution of DIR when no disk
  237.           cache is activated. Padding means that you round up the file size
  238.           when infecting a program. Havoc uses a padding size of 1Fh bytes.
  239.  
  240.      CHKDSK will cause trouble when intercepting i21/11/12. Those faked file
  241.      allocation errors are very easy to detect, and you really should think
  242.      of a way to suppress these errors. The errors are caused by intercepting
  243.      INT 21h/11/12 which gives results that dont match the directory entries.
  244.      An easy way is used by Natas. It checks the PSP of the current program
  245.      at the execution of i21/11/12. At [PSP:2C] you can find the name of the
  246.      current program and if this is CHKDSK Natas doesn't intercept i21/11/12.
  247.      It's also possible to check the name when i21/4B00 is called and disable
  248.      the intercepting of i21/11/12 until CHKDSK is terminated with i21/4C.
  249.      This is done by Tremor.
  250.      But it's very easy to rename CHKDSK and fool a lot of stealth viruses.
  251.      It's possible to intercept CHKDSK, no matter which name it has. Just
  252.      disable the semi-stealth code when i21/32h is called and enable it with
  253.      i21/4B/4C. This call is used by many disk tools and of course by CHKDSK.
  254.      As most other tools use i21/4E/4F it doesn't matter if you disable the
  255.      handling of INT 21h/11/12.
  256.  
  257.  3.2 Full-stealth (sector level)
  258.      This is only interesting for multipartite or boot sector viruses.
  259.      It's very easy to do, most sector viruses have this already.
  260.      But you also should take care of sector WRITES into the MBR. If you
  261.      don't redirect this the virus could be wiped very easily, no matter
  262.      if it's active or not.
  263.      Sometimes sector-stealth viruses just intercept the reading of the
  264.      first sector and won't hide the change if more than one sector is
  265.      read. Take care of this!
  266.      You should also hide the used sectors at cylinder zero on the hard disk
  267.      and the additionally used sectors on floppy disks.
  268.      It's a good idea to block INT 13h/0A/0B (Long read/write) and to use
  269.      stealth at port-level as it is demonstrated with the Megastealth virus.
  270.      For port-level stealth you have to hook INT 76h or INT 15h (function
  271.      91h).  This kind of stealth is effective against many AV programs, for
  272.      example against Invircible's 'LookThrough' feature.
  273.      But keep in mind that port-level stealth can be disabled by just
  274.      resetting INT 15h and INT 76h. (ADinf)
  275.  
  276.      The boot sequence is critical. Take care of QEMM which reloads the
  277.      partition and of TBUTIL which is able to immunize the partition.
  278.      There's two sector viruses which can bypass an immunized partition,
  279.      GoldBug and Havoc. The immunized partition just checks for changes at
  280.      [0:413], INT 13h and the boot sector. GoldBug hooks INT 10h, cleans
  281.      the partition and reinfects it after DOS is installed. Havoc patches the
  282.      partition code directly to avoid warnings.
  283.      Windows with it's 32 bit disk-access will also cause trouble for
  284.      multipartite viruses. Again Havoc and GoldBug are examples how to bypass
  285.      this problem. Havoc adds the command-line parameter '/D:F' when WIN.COM
  286.      is executed, GoldBug intercepts i2F/1605h and removes it's INT 13h
  287.      routine from the interrupt chain until Windows is terminated.(i2F/1606h)
  288.  
  289.  3.3 Polymorphic encryption
  290.      This is used to make detection of the virus more difficult, but many of
  291.      the so called polymorphic engines are a joke and can be detected using
  292.      scan strings with wildcards. Many virus coders are of the opinion that
  293.      an engine should create as many garbage instructions as possible and
  294.      forget to vary the main encryption operands. In fact, SMEG and DSCE
  295.      are very difficult to detect. SMEG because of it's huge decryptors which
  296.      causes TBSCAN and AVP to slow down extremely and DSCE because of it's
  297.      anti-heuristic structures. It just builds the actual decryption loop
  298.      during execution. But both engines add too much senseless rubbish into
  299.      the decryptor. TPE doesn't create quite as complex decryptors but these
  300.      decryptors look more 'smooth', which causes problems for the scanners.
  301.      Here are some examples which you should avoid:
  302.  
  303.      - don't use too many single byte operands like NOP, STI, CLI, CLC, ...
  304.      - don't use branches with zero length offsets (JMP $+2, LOOP $)
  305.      - don't use too many equal MOV REG,xxxx in a row
  306.      - don't use instructions which are not created by TASM/MASM
  307.        That would set another flag for TBSCAN. (Flag '@')
  308.      - don't use the standard anti-debugging tricks like OUT 21,AL
  309.        or INT 1/3 manipulation
  310.  
  311.      Some methods to stop TBSCAN and AVP from decrypting the virus code:
  312.  
  313.      - make several layers of encryption
  314.      - use 286/386 opcodes. This will cause flags with TBSCAN but you could
  315.        use them in the second decryptor level.
  316.      - don't use linear code. Branch alot.
  317.      - use do-nothing i21h functions like AH=4D, 54h, i16H/01 and others.
  318.        TBSCAN will stop decrypting if it finds such calls.
  319.      - Fake PKLITE, DIET or LZEXE decompression headers. TBSCAN will just
  320.        say "LOOKING" and won't scan this file.
  321.      - make use of stack tricks (see encryption of Witch virus)
  322.      - use CPU queue tricks to fool TBAV and AVP
  323.  
  324.        Example:
  325.  
  326.                  ORG 100h
  327.  
  328.                  MOV     CX,200h
  329.                  MOV     CS:BYTE PTR [Lbl_1],5
  330.  Lbl_1:          MOV     AX,666h
  331.  Lbl_2:          MOV     SI,OFFSET Encryption_Area
  332.                  XOR     CS:WORD PTR [SI],AX
  333.                  MOV     CS:BYTE PTR [Lbl_2],0bfh
  334.                  INC     SI
  335.                  INC     SI
  336.                  LOOP    Lbl_1
  337.                  JMP     DI
  338.  
  339.        The first MOV [Lbl_1],5 will turn MOV AX,666 into an ADD AX,666h, and
  340.        the MOV [Lbl_2],0bfh will turn the MOV SI into MOV DI.
  341.  
  342.        In general, the decryptors must look 'smooth' but must also be complex
  343.        enough to fool the scanners. It's not very easy to make a 'successful'
  344.        polymorphic engine. And you must consider if the virus will get too
  345.        long with a complex engine. Speed or complexity, it's your choice.
  346.  
  347.  
  348.  4. RETRO STRUCTURES
  349.     It's very easy to attack AV programs as they usually don't take any
  350.     precautions against direct attacks. I wonder about this. How stupid are
  351.     are those coders? In my opinion it's close to an invitation to break
  352.     their security measures, don't you agree? :)
  353.  
  354.  4.1 Attacking the programs and data files
  355.      The simplest thing is to delete the checksum files like CHKLIST.CPS,
  356.      CHKLIST.TAV, CHKLIST.MS, \BOOT.CPS, \BOOT.TAV, IVB.NTZ, \BOOT.NTZ,
  357.      \PART.NTZ, SMARTCHK.CPS, ANTI-VIR.DAT, \NCDTREE\*.*, \AV.CRC, AVP.CRC
  358.      and others. In most cases the programs create new files without warning
  359.      the user.
  360.  
  361.      You should also take care of the configuration files. If you delete
  362.      Integrity Master's IM.PRM, all old checksums will become useless as IM
  363.      creates random keys every installation. Deleting Invircible's \IV.INI
  364.      and IVB.INI will cause that IVB switch back to old IVB.NTZ file name.
  365.  
  366.      Deleting the scanners is not a good idea because the user will most
  367.      likely notice the virus at once.
  368.  
  369.      An interesting way to infect the partition is to modify \PART.NTZ or
  370.      \BOOT.CPS (or .MS / .TAV). These files are not encrypted. If you insert
  371.      the virus into these files no AV-TSR will warn the user. Next bootup
  372.      IVINIT or BOOTSAFE will warn about the 'changed' partition and most
  373.      likely the user will allow the programs to 'restore' the partition. Poor
  374.      fool. He just infected the system by himself. If your virus has sector
  375.      stealth you should delete \BOOT.CPS or \PART.NTZ when the virus installs
  376.      first time during boot up.
  377.  
  378.  4.2 Faked parameters
  379.      Once your virus is in the hands of the AV crowd it will take just days
  380.      or even hours until their scanners are updated. Even if the virus is so
  381.      heavily polymorphic that they can't write an alogrithmic method for the
  382.      virus they will quickly include a string for the memory checking. But
  383.      imagine if scanners didn't scan memory at all. That would be great! Then
  384.      just add /NOMEM (or equivalents) to the command line at execution of the
  385.      scanner. Keeper.Lemming fooled TBSCAN this way.
  386.  
  387.      Suggested parameters:
  388.  
  389.      F-PROT.EXE:         /NOMEM /COMPAT
  390.      AVP.EXE             /M
  391.      TBSCAN.EXE:         CO NM
  392.      TBSETUP.EXE.        RM
  393.      SCAN.EXE:           /NOMEM (/BOOT)
  394.      AVSCAN.EXE:         /NM
  395.      ANTIVIR.EXE:        /NM
  396.      IVB.EXE:            /S or /V
  397.      VSAFE.*             /D
  398.      TSAFE.*             /D
  399.      WIN.COM:            /D:F (For multipartite viruses)
  400.  
  401.      If you add CO to TBSCAN's command line then don't forget to patch the
  402.      screen display of 'FILE SYSTEM: DOS' back to 'FILESYSTEM: OWN'.
  403.  
  404.  4.3 Disable the shields
  405.      Everyone knows how to disable VSAFE:
  406.  
  407.      MOV AX,FA01h
  408.      MOV DX,5945H
  409.      INT 16h
  410.  
  411.      You can find this call in nearly every new virus. But obviously the
  412.      virus coders haven't noticed the change in VSAFE (CPAV) and TSAFE (TNT).
  413.      This call is now useless!
  414.  
  415.      A more effective way to disable TSAFE, TBDRIVER, SDRES, NAVTSR and
  416.      others is to patch the TSR in memory.
  417.      TBDRIVER could be disabled very easily. Since version 6.2x upto 6.3x
  418.      and newer versions NOTHING has changed in this TSR. The TBDRIVER-INT 21h
  419.      looks like this:
  420.  
  421.      EB 05        JMP Label_1
  422.      EA xxxx yyyy JMP FAR PTR Old_Int21
  423.      Label_1:
  424.  
  425.      Just patch the 5 to 0 and TBDRIVER is disabled. No more tracer blocking,
  426.      memory checking, file control and scanning. Well, there is a problem
  427.      with this patching. Where is the TSR located?
  428.      If the user loaded other TSRs after TBDRIVER the INT 21 code is hidden.
  429.      Well, what about tracing through INT 21 and checking the code during
  430.      the tracing process? This works fine, as demonstrated in Havoc.
  431.      If you don't want to use a tracer then scan through the MCB chain.
  432.      TBUTIL immunized partitions, VSAFE/TSAFE and NAVTSR could be disabled
  433.      in the same way.
  434.  
  435.      If this is too much code then just call i21/4B00 with a non-existant
  436.      name or not enough memory free after you hooked INT 21. TBMEM stores the
  437.      current memory map and interrupt list when i21/4B00 is called and
  438.      compares it when the program terminates with i21/4C. The faked i21/4B00
  439.      call will force TBMEM to 'forget' the clean environment and your virus
  440.      can install without any problem.
  441.  
  442.      Another possible solution is to stop installation and infection when the
  443.      virus notices AV-TSRs in memory. This is very easy, for example check
  444.      the MCB chain for names like 'VSAFE', 'TBDRIVER' and so on.
  445.      The TBAV TSRs can be detected by opening 'TBDRVXXX', 'TBDSKXXX' or
  446.      'TBFILXXX'. This are names of the installed devices and if you can open
  447.      them, the TSRs are active in memory.
  448.  
  449.  4.4 Tunneling
  450.      Well, tracing is not the best way to find the original i21 and i13
  451.      entries. All good AV-TSRs can disable tracers. There's a much better way
  452.      which needs DOS 5.0 up to 6.22 and the DOS=HIGH setting.
  453.      (It's also possible with DOS=LOW)
  454.  
  455.      Well, just take a look at this:
  456.  
  457.      MOV AH,52h
  458.      INT 21h
  459.      MOV BX,109Eh
  460.  
  461.      Execute this and look at ES:BX. This is the entry-point into the DOS
  462.      kernel. This method works fine with EMM386, QEMM or 386MAX and there
  463.      are no other TSRs behind this, only plain DOS.
  464.      If you are careful you could check if this entry-point looks like:
  465.  
  466.      90             NOP
  467.      90             NOP
  468.      E8 xx xx       CALL xxxx
  469.      2E FF 2E yyyy  JMP FAR CS:[yyyy]
  470.  
  471.      There's no similar way for INT 13, but you could use direct port access
  472.      instead.
  473.  
  474.  4.5 Memory and MCB stealth
  475.      Some users have eyes (yes, no joke :) and will see that the amount of
  476.      free memory is decreasing. A way around this problem is to release the
  477.      memory of the virus during the execution of the system info tools.
  478.      Just intercept i21/4B00 and check for CHkdsk, MEm, SYsinfo, SI, MFt, MI
  479.      and others. If such a tool is being executed set the MCB marker back to
  480.      zero and at i21/4C00 back again to 8 (system area).
  481.  
  482.      You maybe already noticed that your virus couldn't infect TBSCAN.EXE
  483.      without setting off it's selfcheck alarm, no matter how good your full-
  484.      stealth code is. The first step is to add 'CO' to the command line, but
  485.      TBSCAN.EXE also checks it's MCB size in memory. Well, no problem at all.
  486.      Just subtract the virus paragraph size from the word at [MCB:3] before
  487.      returning to the host. This is only neccessary for EXE files which have
  488.      the MAXIMUM PARAGRAPHS NEEDED entry set below FFFFh. COM programs always
  489.      take all free memory and can't be MCB-stealthed.
  490.  
  491.      Example: (taken from Havoc)
  492.  
  493.                  MOV     AH,62h
  494.                  INT     21h
  495.                  MOV     ES,BX
  496.  
  497.                  PUSH    BX
  498.                  DEC     BX
  499.                  MOV     DS,BX
  500.                  MOV     BX,Old_MCB_Length
  501.                  CMP     BH,50h
  502.                  JA      Lbl_1
  503.                  MOV     AX,DS:WORD PTR [3]
  504.                  SUB     AX,BX
  505.                  SUB     DS:WORD PTR [DI+12h],AX
  506.                  MOV     AH,4Ah
  507.                  INT     21h
  508.      Lbl_1:      POP     BX
  509.  
  510.      How to calculate 'Old_MCB_Length':
  511.  
  512.                  MOV     AX,WORD PTR [MAX_PARA_NEED]
  513.                  CMP     AH,FFh
  514.                  JE      LBL_2
  515.                  MOV     AX,WORD PTR [SIZE_IN_PAGES]
  516.                  CWD
  517.                  MOV     CX,20h
  518.                  MUL     CX
  519.                  SUB     AX,WORD PTR [PARA_IN_HEADER]
  520.                  ADD     AX,WORD PTR [MAX_PARA_NEED]
  521.                  ADD     AX,10h
  522.      Lbl_2:      MOV     WORD PTR [Old_MCB_Length],AX
  523.  
  524.      MAX_PARA_NEED, SIZE_IN_PAGES and PARA_IN_HEADER are taken from the
  525.      uninfected EXE header.
  526.  
  527.  4.5 Anti-Bait
  528.      If an AV researcher gets your virus he most likely wants to infect his
  529.      own baits. And there're a lot of programs which create baits in order
  530.      to catch active viruses. To make their job a little bit harder your
  531.      virus shouldn't infect files smaller than 5000 or even 10000 bytes and
  532.      ignore files that have the current system date (month and year) set.
  533.      Baits are usually newly created and have the current date as time stamp.
  534.      If your virus avoid such files, the baits will never get infected.
  535.  
  536.  4.6 Slow polymorphic
  537.      Normal polymorphic engines mutate with every new infected file. But
  538.      remember when Tremor popped up in March '93. At this point the virus
  539.      was already well-known to most of the AV community. But several months
  540.      later F-PROT and TBSCAN still couldn't detect Tremor reliably. The
  541.      reason for this is that Tremor mutates quite slowly. If you infect some
  542.      programs on the same date the decryptors won't look much different.
  543.      But then set the system date to the next day or month. Surprise! Now the
  544.      decryptors look completely different. Usually the AV researchers don't
  545.      have enough time to test a virus completely and because of this F-PROT
  546.      and TBSCAN missed Tremor in many files. Tremor's successor Havoc uses
  547.      the same way to confuse the researchers and again F-PROT and TBSCAN
  548.      still don't detect 100 percent of all samples.
  549.      But you could make the research even more difficult. Tremor checks the
  550.      system time and date during every infection in order to randomize the
  551.      decryptor construction. So it's very easy to code a bait-launcher which
  552.      varies the time and date before it creates and executes a new bait file.
  553.      But what will happen if the virus generates new random numbers at every
  554.      installation ONLY? This will slow down the polymorphic engine extremely
  555.      but the researchers have to restart the computer for every new bait file
  556.      which should be infected with a different encryption.
  557.      Well, most AV companies create more than 10000 files for one polymorphic
  558.      virus. Imagine the time they must waste now. 10000 times rebooting!
  559.      Believe me, this will drive some of the AV researchers mad :)
  560.  
  561.  4.7 'Non-curable' infections
  562.      Most viruses infect files in the standard way. They just modify the file
  563.      header and add the virus code at the file end. This kind of infection
  564.      can be cured very fast with TBCLEAN, NAV and Invircible which use data
  565.      files for curing. To prevent this you could infect files like Commander
  566.      Bomber or One_Half do. Insert pieces of code into random positions.
  567.      This is very effective, but will make full-stealth impossible.
  568.  
  569.      Multipartite viruses like Stoned.Empire.Monkey.B, or GoldBug or have
  570.      a method to prevent simple removing with FDISK /MBR. First of all your
  571.      virus must have sector-stealth. The trick is to wipe the partition data
  572.      except for the virus code and the boot marker AA55h. If the virus isn't
  573.      active the hard disk becomes inaccessible. If the user then tries
  574.      FDISK /MBR all data is lost! Remember, without sector-stealth this
  575.      can't work and the system will hang next bootup.
  576.      One_Half has another life insurance. It encrypts the hard disk, one
  577.      sector at every system restart. Because it uses a random key all data 
  578.      gets lost if you just remove the virus from the partition without
  579.      decrypting the rest of the partition.
  580.  
  581.  
  582.  5. SURVIVAL AND INFECTION STRATEGY
  583.     I think I don't have to waste space to tell you that non-resident viruses
  584.     are the most boring thing one could do. Agreed?
  585.     Well, some virus coders think that infecting as many programs as possible
  586.     in the shortest possible time intervall makes their virus better and
  587.     spread much further. What I'm talking of is commonly called
  588.     fast-infector. (Or was it piggybacking? :)
  589.     In my opinion fast-infection is also the fastest way to get the virus
  590.     detected by even VERY stupid users. Fast-infectors slow down the system
  591.     in such a way that their detection is just a question of time.
  592.     Invircible even checks the free disk space before and after opening
  593.     programs during it's checks.
  594.     The next point is what victims the virus should infect. Viruses that only
  595.     infect COM don't spread far. Just have a look into the directories
  596.     of your hard disk. Count COM files and compare it with the number of
  597.     possible EXE victims. Infecting SYS files is a interesting job to do, but
  598.     will never make the virus spread further than without that ability.
  599.     Just a waste of space.
  600.     The same goes for strange and incompatible infection methods like DIR-2,
  601.     Circus Cluster or Assassin use. The routines they use are very effective
  602.     concerning their stealth abilities. But DIR-2 crashes with DOS 5.0 or
  603.     above, Circus Cluster will most likely never find fitting EXE files and
  604.     Assassin will be wiped with the next execution of DEFRAG or SPEEDISK.
  605.     Again, this is pure waste of time. Such viruses will never spread far.
  606.     Viruses using 'standard' methods of infection spread furtherest as the
  607.     past shows.
  608.     It's a good idea to stop infecting when the virus notices the presence of
  609.     advanced antivirus software like TBAV. In this case the user is most
  610.     likely advanced and will notice the virus quite soon.
  611.     And as some viruses already do, disabling the stealth code when using
  612.     backup software (BACKUP, CPBACKUP) or archiver like ARJ, PKZIP or LHA
  613.     will help to spread the virus even further. If the virus manages to
  614.     infiltrate into the users backups it could survive much longer.
  615.     Finally, don't upload your virus to any VX BBS. Almost every AV guy has
  616.     access to a lot of these boards and your virus will be in the hands of
  617.     the AV researchers within little time. In this way, it will never spread
  618.     in the wild.
  619.  
  620.  
  621.  6. THE 'PERFECT' VIRUS
  622.     The following text has been extracted from 'POSSIBLE VIRUS ATTACKS' by
  623.     Vesselin Bontchev, Virus Test Center. (Well, everyone should know him)
  624.     It contains some good ideas, so why not use them?
  625.     Thanks Vesselin! :)
  626.  
  627.  --------------------------------------------------------------------------
  628.  
  629.  Almost all the attacks described above have been "tried" by the virus
  630.  writers, by implementing them in some virus - at least to demonstrate
  631.  that it is possible and "can be done." However, most of these viruses
  632.  have been "demonstration-only" and not able to spread widely.  Let's
  633.  try to imagine what can be done by just combining the different kinds
  634.  of attack listed above.  This (imaginary) virus will be a slow
  635.  infector, so we shall name it Kuang [Gibson].  Since it combines only
  636.  the currently known infection techniques, it is just a matter of time
  637.  before such viruses begin to appear.  The reader is invited to try to
  638.  figure out him/herself how well such virus will spread and how well
  639.  prepared is the line of anti-virus defense that s/he currently uses
  640.  against such viruses.
  641.  
  642.  Kuang comes with an infected utility that you get from a BBS or a
  643.  public archive site, from the boot sector of a data-only diskette that
  644.  you have forgotten in your boot drive, or from a shrink-(re)wrapped
  645.  commercial package produced by a company that decides to save some
  646.  money on the quality assurance procedures.  When you execute it, it
  647.  installs itself in memory in such a way that comparing the listings of
  648.  MEM/DEBUG before and after the RAM infection will not show any
  649.  differences.  This is possible by installing the virus in some holes
  650.  in the operating system (like the Tiny virus), in the video memory
  651.  (like the StarShip virus), and some other places.
  652.  
  653.  After it becomes active, Kuang does not infect anything at once.  If
  654.  you now turn your system off, it will be gone - until the next time
  655.  you execute the infected utility.  However, it carefully watches for
  656.  any executable object being modified and infects it.  Since it is a
  657.  multi-partite virus, it is able to infect almost anything - boot and
  658.  master boot sectors, COM and EXE files, overlays, device drivers (like
  659.  the SVC 6.0 virus), .OBJ files, libraries...  The only condition is
  660.  that some modification is performed with the object - that is, a
  661.  Create or Write occurs to it (like the Darth Vader, StarShip and
  662.  Compiler viruses do).
  663.  
  664.  The virus will spread slowly - mostly when the user copies files or
  665.  formats diskettes.  When infecting the files, Kuang uses multiple
  666.  infection strategies.  It tries not to modify the intended file size -
  667.  if the file contains a block of zeroes (or even of any single byte
  668.  that is repeated over and over), the virus uses this area to put its
  669.  body (like the Phoenix and Squisher viruses do).  If an EXE file has a
  670.  sufficiently large EXE header, the virus compresses the relocation
  671.  items (like the Phoenix.2000 virus does) in order to free space for
  672.  its body.
  673.  
  674.  Kuang watches for a file with an archive extension (ARC, ARJ, HYP,
  675.  LHZ, PAK, ZIP, or ZOO) for being opened.  When this happens, the virus
  676.  changes its behavior.  It becomes a fast infector - it begins to
  677.  infect all executable files (executable in the broad sense, including
  678.  .OBJ files and libraries) when they are opened (not only when they are
  679.  modified) and to disinfect them when they are closed (unless they are
  680.  newly created).  This behavior remains until the archive file is
  681.  closed.  This will ensure that all files being archived will go into
  682.  the archive infected and all files extracted from the archive will be
  683.  infected too.
  684.  
  685.  During the infection/disinfection of the files during archiving as
  686.  described above, the virus uses the tunneling technology (like the
  687.  Frodo virus) to avoid the possibly present monitoring programs.  (This
  688.  technique is not needed during the normal slow infection, since then
  689.  the user will not be surprised by a message that a file is about to be
  690.  modified - because it was the user him/herself who initiated the
  691.  modification.)
  692.  
  693.  Furthermore, while active in memory, Kuang uses the stealth technology
  694.  (like the Number of the Beast virus), in order to prevent from being
  695.  detected by simply comparing the copy of the file with the original or
  696.  by using the /V switch of the COPY command.
  697.  
  698.  Just in case somebody detects it, Kuang uses armouring tricks (like
  699.  the Whale or Fish viruses), in order to make the code more difficult
  700.  to disassemble, debug, and understand.
  701.  
  702.  Additionally, it uses a polymorphic technique, comparable with the one
  703.  used in the V2Px viruses, or in Dark Avenger's Mutating Engine (MtE),
  704.  so that even when detected and disassembled, it will be extremely
  705.  difficult to produce a scanner that will be able to locate and
  706.  recognize it with 100 reliability...
  707.  
  708.  At last, the virus can be made to be Novell NetWare-aware and to
  709.  exploit any security holes in the settings of the directory and file
  710.  rights.  As described in [Cohen92], under Novell NetWare it is not
  711.  trivial to setup all the protection rights and attributes in a way
  712.  that will make virus spread impossible.  There are many LANs out
  713.  there, which are not configured in a secure way.  Therefore, a clever
  714.  virus should be able to exploit this.
  715.  
  716.  --------------------------------------------------------------------------
  717.  
  718.     I don't fully agree with that text. Slow infectors can be intercepted by
  719.     AV-TSRs. At least diskettes and the partition should be infected as
  720.     fast as possible to allow the virus to activate at the next system
  721.     restart. Also, it's nearly impossible to have full-stealth combined with
  722.     a header infecting virus. Vesselin obviously never wrote complex viruses
  723.     before. :) Infecting OBJ or libaries is interesting, but a waste of space
  724.     which should be used for a proper polymorphic engine instead.
  725.     What I would call 'heavy impact' is a virus which infects EXE programs,
  726.     the partition and boot sectors of disks, with full-stealth routines, a
  727.     good polymorphic engine and enough retro abilities to disable the most
  728.     common AV programs. This is not very difficult, and One_Half, Havoc,
  729.     Gold_Bug and Natas are already designed in this way.
  730.  
  731.  
  732.  7. POLYMORPHIC CODE CONSTRUCTION
  733.     Finally, I have an idea for those who are still interested in writing
  734.     complex viruses. Up to now, every virus construction kit is very
  735.     primitive. The better ones include polymorphic engines, but so far I've
  736.     seen neither BW or NLRG caused any problems for AVP. I have a better idea
  737.     to make detection impossible. Why not use polymorphic code generation
  738.     instead of just adding polymorphic encryption?
  739.     AVP and TBSCAN simply trace through the decryptors and scan the virus
  740.     with normal scan strings. But imagine if the virus code itself is changed
  741.     every time? Of course, this is too complex for a virus and must be
  742.     included in a construction kit.
  743.  
  744.     Example:
  745.  
  746.     Instead of simply using
  747.  
  748.          MOV     AH,4Eh
  749.          MOV     CX,37h
  750.          LEA     DX,[BP+xxxx]
  751.          INT     21h
  752.  
  753.     the construction engine should be able to build things like this:
  754.  
  755.          MOV     CL,37h
  756.          MOV     AL,4Eh
  757.          XCHG    AL,AH
  758.          MOV     CH,0
  759.          MOV     DX,BP
  760.          ADD     DX,xxxx
  761.          INT     21h
  762.  
  763.     or
  764.  
  765.          SUB     CX,CX
  766.          OR      CL,37h
  767.          MOV     AH,1Eh
  768.          ADD     AH,30h
  769.          CWD
  770.          OR      DX,BP
  771.          SUB     DX,-xxxx
  772.          PUSHF
  773.          CALL    CS:DWORD PTR [Int_21]
  774.  
  775.     Each instruction must be done randomly every time you create a new virus.
  776.     Don't use any fixed pattern, or scan strings will be possible again.
  777.  
  778.     If you do this for the complete virus, code detection will be VERY
  779.     difficult. The AV researchers will have to invoke your kit many times in
  780.     a row to get all possible mutations and if you use slow polymorphic code
  781.     generation they'll probably never find all possible mutations.  Code
  782.     decryption will not help against this. Even better, your virus doesn't
  783.     need a lengthy polymorphic engine any more!
  784.     Think twice, this is the final impact for the AV comunity.
  785.  
  786.  
  787.                               END OF DOCUMENT
  788.  
  789.  
  790.                       
  791.